<template>
  <div class="dialog">
        <div class="background" @click="giveUp()"></div>
        <div class="dialogdiv">
            <label>投诉处理</label>
            <div class="message">
                <div class="perdiv">
                    <label><strong>起诉用户&nbsp;&nbsp;</strong></label>
                    <input type="text" disabled :value="$store.state.appealAdmin.reportNickName">
                </div>
                <div class="perdiv">
                    <label><strong>被诉用户&nbsp;&nbsp;</strong></label>
                    <input type="text" disabled :value="$store.state.appealAdmin.reportedNickName">
                </div>
                <div class="perdiv">
                    <label><strong>投诉状态&nbsp;&nbsp;</strong></label>
                    <select disabled>
                        <option>未审核</option>
                        <option>已通过</option>
                        <option>未通过</option>
                    </select>
                </div>
                <div class="perdiv">
                    <label><strong>投诉时间&nbsp;&nbsp;</strong></label>
                    <input type="text" disabled :value="$store.state.appealAdmin.time">
                </div>
                <div class="photo food">
                    <div class="photoText">
                        <label><strong>动态图片</strong></label>
                    </div>
                    <div class="pictures">
                        <span
                        v-for="(photo,index) in appealImg" 
                        :key="index"
                        >
                            <img :src="photo">
                        </span>
                    </div>
                </div>
                <div class="text">
                    <div class="textTop">
                        <label><strong>动态内容</strong></label>
                    </div>
                    <div class="textarea">
                        <span>
                            {{appeal.content}}
                        </span>
                    </div>
                </div>
                <div class="text">
                    <div class="textTop">
                        <label><strong>投诉原因</strong></label>
                    </div>
                    <div class="textarea">
                        <span>
                            {{$store.state.appealAdmin.reason}}
                        </span>
                    </div>
                </div>
                <div class="perdiv buttons">
                    <button class="yesbtn" @click="examine(1)">通过</button>
                    <button class="deleteUser" @click="examine(2)">不通过</button>
                    <button class="giveup" @click="giveUp()">取消</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import axios from "axios"
export default {
    name: 'FoodDialog',
    data(){
        return{
            appeal:[]
        }
    },
    methods:{
        giveUp(){
            this.$store.state.dialog = 0
        },
        search(id){
            // 请求前更新list数据
            axios.get(`http://123.57.251.41:8080/audit/getPost?bodyId=${id}`,{headers:{'Authentication-Token': JSON.parse(sessionStorage.getItem("token"))}}).then(
                response =>{
                    console.log('请求成功了')
                    console.log(response.data.data)
                    this.appeal = response.data.data
                },
                error =>{
                    alert("请求失败了",console.log(error))
                }
            )
        },
    },
    computed:{
        Focuse(){
            return this.$store.state.dialog
        },
        appealImg(){
            if(this.appeal.imgs == ''){
                return ["http://tva1.sinaimg.cn/large/006APoFYjw1favb6avdpoj30dc0dcwen.jpg"]
            }else if(this.appeal.imgs == null){
                return ["http://tva1.sinaimg.cn/large/006APoFYjw1favb6avdpoj30dc0dcwen.jpg"]
            }else{
                var m = this.appeal.imgs.split(",")
                return m
            }
        },
        examine(b){
            axios.post(`http://123.57.251.41:8080/audit/audit-post?code=${b}&reportTime=${this.$store.state.appealAdmin.time}&reportedUser=${this.$store.state.appealAdmin.reportedNickName}&toUser=${this.$store.state.appealAdmin.reportNickName}`,{headers:{'Authentication-Token': JSON.parse(sessionStorage.getItem("token"))}}).then(
                response =>{
                    console.log('成功')
                    console.log(response.data.data.list)
                    this.$store.state.dialog = 0
                },
                error =>{
                    console.log(b)
                    alert("失败",console.log(error))
                    this.$store.state.dialog = 0
                }
            )
        }
    },
    watch:{
        Focuse:{
            immediate:true,
            deep:true,
            //hander在isHot发生改变的时候调用
            handler(newValue,oldValue){
                console.log(newValue,oldValue)
                if(newValue == 2){
                    this.search(this.$store.state.appealAdmin.bodyId)
                }
            }
        }
    }
}
</script>

<style>

</style>